package com.lindroy.androidplayer.ui.main.fragment

import android.os.Bundle
import androidx.core.view.forEach
import com.lindroy.androidplayer.R
import com.lindroy.androidplayer.base.BaseFragment
import com.lindroy.androidplayer.databinding.FragmentMainBinding
import com.lindroy.androidplayer.ui.adapter.MainTabAdapter
import com.lindroy.androidplayer.utils.navigator.SmoothNavHostFragment

/**
 * @author Lin
 * @date 2022/1/29
 * @function
 */
class MainFragment : BaseFragment<FragmentMainBinding>() {
   

    override fun FragmentMainBinding.initView(savedInstanceState: Bundle?) {
        vpMain.isUserInputEnabled = false
        vpMain.offscreenPageLimit = bottomNav.menu.size()
        vpMain.adapter = MainTabAdapter(this@MainFragment).apply {
            val tabList = arrayListOf<Int>()
            bottomNav.menu.forEach {
                tabList.add(it.itemId)
            }
            setData(tabList)
        }
    }

    override fun initData() {
    }

    override fun FragmentMainBinding.initListener() {
        bottomNav.setOnItemReselectedListener {}
        /*vpMain.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                super.onPageSelected(position)
                if (tabIds[position] == R.id.mineFragment) {
                    mActivity.setStatusBarLightMode()
                } else {
                    mActivity.setStatusBarDarkMode()
                }
            }
        })*/
        bottomNav.setOnItemSelectedListener {
            vpMain.setCurrentItem(it.order, false)
            true
        }
    }
}